Conversation
| temp->next = temp; | ||
| temp->prev = temp; |
There was a problem hiding this comment.
В этой задаче циклический список несколько излишний :)
| while (walker->next != list->head) { | ||
| walker = walker->next; | ||
| } |
There was a problem hiding this comment.
И получится head->prev, только за линейное время. Тем более что у Вас ещё есть tail
| list->tail = temp; | ||
| walker->next = temp; | ||
| temp->prev = walker; | ||
| temp->next = list->head; |
| } | ||
| list->tail = walker->prev; | ||
| free(walker); | ||
| walker = NULL; |
There was a problem hiding this comment.
Это бесполезно, потому что строчкой ниже мы уйдём на следующую итерацию, где walker будет уже другим. Можно хоть 239 тут в него присвоить :)
| while (list->head != list->tail) { | ||
| Node* walker = list->head; | ||
| while (walker != list->tail) { | ||
| walker = walker->next; | ||
| } | ||
| list->tail = walker->prev; | ||
| free(walker); | ||
| walker = NULL; | ||
| } |
There was a problem hiding this comment.
Удаление списка за O(n^2) вообще без какой-то видимой причины :) Прямо обязательно удалять из хвоста, при этом несмотря на цикличность и двусвязность списка попадать в хвост полным проходом по списку — это неправильно. Можно было просто while (list->head != list->tail) { Node *temp = list->head; list->head = list->head->next; free(temp); }
| List* createList(void); | ||
|
|
||
| //Check is symmetrical list | ||
| int isSymmetricalList(List* list); No newline at end of file |
| } | ||
| Node* walkerHead = list->head; | ||
| Node* walkerTail = list->tail; | ||
| while (walkerTail != list->head && walkerHead != list->tail) { |
There was a problem hiding this comment.
А мне кажется, что они могли бы двигаться, пока не встретились. А так они список по сути дважды проходят.
| #include <stdbool.h> | ||
| #include "list.h" | ||
|
|
||
| int workWithFile(char fileName[]) { |
There was a problem hiding this comment.
| int workWithFile(char fileName[]) { | |
| int workWithFile(const char *fileName) { |
| List* list = createList(); | ||
| while (fscanf(file, "%d", &number) > 0) { | ||
| if (insert(list, number) == -1) { | ||
| return -2; |
There was a problem hiding this comment.
Так уже выделенная под список память не удалится
| bool test() { | ||
| int result = workWithFile("test.txt"); | ||
| return result == 1; | ||
| } |
There was a problem hiding this comment.
Надо было ещё на несимметричность хоть один тест :)
No description provided.